<template>
	<view>
		<ikz-loading :css-data="loading_css"></ikz-loading>
		<view class="ikz-top-bg">
			<image class="ikz-top-bg-img" :src="service_img"></image>
		</view>
		<view class="txt-box">
			<image src="/static/index/index-le.png" style="width: 80rpx;height: 80rpx;" mode=""></image>
			<view class="title_txt">
				表白墙
			</view>
		</view>

		<view class="tabbar_txt">
			<view class="left_box">
				<view class="tab-item" v-for="(item,index) in yuelist" :key="index" @click="hah(item,index)">
					<view :class="['tab-item', { selected: selectedIndices == index ? 'selected':''}]">
						{{ item.cate_name }}
					</view>
				</view>
			</view>

			<view class="right-box" @click="toguanli">
				<image src="/static/index/dongtai.png" style="width: 22rpx;height: 22rpx;" mode=""></image>
				<view class="dtgl">
					动态管理
				</view>
			</view>
		</view>

		<view class="cenbox">
			<scroll-view scroll-y :style="{ height: windowHeight }" @scrolltolower="onreachBottom">
				<view class="itembox" v-for="(item,index) in list" :key="index" @click="todetails(item)">
					<view class="topbox">
						<image :src="item.avatar" style="width: 72rpx;height: 72rpx;border-radius: 50%;" mode="">
						</image>
						<view class="r-box">
							<view class="nametxt">
								{{item.nickname}}
							</view>
							<view class="timetxt">
								{{item.time}}发布
							</view>
						</view>
					</view>

					<view class="centerbox">
						<view class="dongtaitxt">
							{{item.content}}
						</view>
						<view class="imgbox">
							<image :src="i" v-for="(i,k) in item.images" :key="k"
								style="width: 220rpx;height: 220rpx;border-radius: 16rpx;margin-bottom: 16rpx;margin-right: 10rpx;" mode=""></image>
						</view>

					</view>
					
					<view class="fpzbox">
						<view class="fenxiang">
							<image src="/static/index/fenxiang.png" style="width: 26rpx;height: 26rpx;" mode=""></image>
							<view class="nums">
								{{item.xyb_posts_collection}}
							</view>
						</view>
						<view class="pinglun">
							<image src="/static/index/pinglun.png" style="width: 26rpx;height: 26rpx;" mode=""></image>
							<view class="nums">
								{{item.comment}}
							</view>
						</view>
						<view class="zan">
							<image src="/static/index/dianzan.png" style="width: 26rpx;height: 26rpx;" mode=""></image>
							<view class="nums">
								{{item.give}}
							</view>
						</view>
					</view>
				</view>
			</scroll-view>

		</view>
		
		<view class="favu" @click="tifabu">
			<image src="/static/index/fabu.png" style="width: 116rpx;height: 116rpx;border-radius: 50%;" mode=""></image>
		</view>
	</view>
</template>

<script>
	import ikz from '@/pages/Common/tools.js';
	export default {
		data( ) {
			return {
				adminImgPath: getApp( ).globalData.adminImgPath,
				loading_css: {
					display: 'flex'
				},
				service_img: '/static/index/bg.png',
				yuelist: [ {
					cate_name: '最新'
				}, {
					cate_name: '最热'
				} ],
				selectedIndices: 0,
				windowHeight: 0,
				list:[],
				page:1,
				limit:10
			};
		},
		onLoad( ) {
			var _this = this
			uni.getSystemInfo( {
				success: function( res ) {
					_this.windowHeight = res.windowHeight - 146 + 'px';
					console.log( res, '屏幕高度' );
				}
			} )
		},
		onShow() {
			this.init()
		},
		methods: {
			hah( item, index ) {
				console.log( index, '每一项' );
				this.selectedIndices = index
				if(this.selectedIndices== 0){
					this.init()
				}else {
					var path = '/xyb/posts/posts/index';
					var data = {
						page: this.page,
						limit: this.limit,
						recommend:' ',
						token: uni.getStorageSync( 'local_user_session' ),
					}; 
					ikz.requestPost( path, data, res => {
						console.log(res,'rrrr');
						if ( res.data.code ) {
							this.list = res.data.data.data
						} else {
							uni.showModal( {
								title: '提示',
								content: res.data.msg,
								showCancel: false,
								success: function( res ) {}
							} );
						}
					} )	
				}
			},
			onreachBottom( e ) {
				console.log( e, 'e' );
			},
			tifabu(){
				uni.navigateTo({
					url:'/pages/Home/lovefabu/lovefabu'
				})
			},
			todetails(item){
				uni.navigateTo({
					url:'/pages/Home/dongtaidetails/dongtaidetails?id='+item.id
				})
			},
			toguanli(){
				uni.navigateTo({
					url:'/pages/Home/mydetails/mydetails'
				})
			},
			init(){
				var path = '/xyb/posts/posts/index';
				var data = {
					page: this.page,
					limit: this.limit,
					recommend:'recommend',
					token: uni.getStorageSync( 'local_user_session' ),
				}; 
				ikz.requestPost( path, data, res => {
					console.log(res,'rrrr');
					if ( res.data.code ) {
						this.list = res.data.data.data
					} else {
						uni.showModal( {
							title: '提示',
							content: res.data.msg,
							showCancel: false,
							success: function( res ) {}
						} );
					}
				} )	
			}
			
		},
	}
</script>

<style lang="scss" scoped>
	.ikz-top-bg {
		position: fixed;
		top: 0px;
		left: 0px;
		z-index: -1;
	}

	.ikz-top-bg-img {
		width: 750rpx;
		height: 430rpx;
	}

	.txt-box {
		width: 100%;
		height: 82rpx;
		// margin: 110rpx auto 0px;
		margin-top: 90rpx;
		display: flex;

		.title_txt {
			width: 156rpx;
			height: 82rpx;
			font-weight: 500;
			font-size: 32rpx;
			color: #000000;
			text-align: center;
			line-height: 82rpx;
			margin-left: 258rpx;
			z-index: 2;
		}
	}



	.tabbar_txt {
		width: 100%;
		height: 62rpx;
		margin-top: 10rpx;
		// margin-left: 34rpx;
		padding: 0 30rpx;
		box-sizing: border-box;
		z-index: 2;
		display: flex;
		align-items: center;
		justify-content: space-between;

		.left_box {
			width: 306rpx;
			height: 62rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 4rpx;
			box-sizing: border-box;

			.tab-item {
				width: 64rpx;
				height: 58rpx;
				line-height: 62rpx;
				text-align: center;
				font-weight: 400;
				font-size: 28rpx;
				color: #222222;

				.selected {
					/* 选中时的样式，比如背景色为红色 */
					font-weight: bold;
					color: #222;
					font-size: 32rpx;
					border-bottom: 8rpx solid #247EFF;
				}
			}
		}

		.right-box {
			width: 136rpx;
			height: 58rpx;
			display: flex;
			align-items: center;

			.dtgl {
				width: 104rpx;
				height: 58rpx;
				font-weight: 400;
				font-size: 26rpx;
				color: #222222;
				text-align: left;
				line-height: 58rpx;
				margin-left: 8rpx;
			}
		}

	}

	.cenbox {
		width: 100%;
		min-height: 500rpx;
		margin-top: 42rpx;
		padding: 0 30rpx;
		box-sizing: border-box;
		background-color: #fff;

		.itembox {
			width: 100%;
			min-height: 371rpx;
			padding: 26rpx 0;
			box-sizing: border-box;
			border-bottom: 1rpx solid #F5F5F5;

			.topbox {
				width: 100%;
				height: 72rpx;
				display: flex;
				align-items: center;

				.r-box {
					width: 600rpx;
					height: 72rpx;
					margin-left: 8rpx;

					.nametxt {
						width: 100%;
						height: 38rpx;
						font-weight: 500;
						font-size: 26rpx;
						color: #222222;
						text-align: left;
					}

					.timetxt {
						width: 100%;
						height: 34rpx;
						font-weight: 300;
						font-size: 22rpx;
						color: #AFAFAF;
						text-align: left;
					}
				}
			}

			.centerbox {
				width: 100%;
				min-height: 220rpx;
				margin-top: 26rpx;
				box-sizing: border-box;

				.dongtaitxt {
					width: 100%;
					min-height: 38rpx;
					font-weight: 400;
					font-size: 26rpx;
					color: #000000;
					text-align: left;
					margin-bottom: 24rpx;
				}

				.imgbox {
					width: 100%;
					min-height: 220rpx;
					display: flex;
					flex-wrap: wrap;
				}
			}
			
			.fpzbox{
				width: 100%;
				height: 92rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 0 100rpx;
				box-sizing: border-box;
				
				.fenxiang{
					width: 100rpx;
					height: 92rpx;
					display: flex;
					align-items: center;
					.nums{
						width: 100%;
						height: 36rpx;
						font-weight: 400;
						font-size: 24rpx;
						color: #666666;
						text-align: left;
						margin-left: 6rpx;
					}
				}
				.pinglun{
					width: 100rpx;
					height: 92rpx;
					display: flex;
					align-items: center;
					.nums{
						width: 100%;
						height: 36rpx;
						font-weight: 400;
						font-size: 24rpx;
						color: #666666;
						text-align: left;
						margin-left: 6rpx;
					}
				}
				.zan{
					width: 100rpx;
					height: 92rpx;
					display: flex;
					align-items: center;
					.nums{
						width: 100%;
						height: 36rpx;
						font-weight: 400;
						font-size: 24rpx;
						color: #666666;
						text-align: left;
						margin-left: 6rpx;
					}
				}
			}
		}
	}

	.favu{
		width: 116rpx;
		height: 116rpx;
		position: fixed;
		bottom: 250rpx;
		right: 34rpx;
	}
</style>